﻿using System;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using mojoPortal.Web.RS.PRM.AppCode.Lib;

namespace mojoPortal.Web.RS.PRM.Controls
{
    public partial class OwnerHeaderControl : RSBaseUserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public bool LoadOwnerHeader(int companyid, int ownerid)
        {
            bool bHasValue = false;
            lblOwnerID.Text = ownerid.ToString();

            if (companyid > 0 && ownerid > 0)
            {
                String strSQL = "select ownerid, firstname + ' ' + middlename + ' ' + lastname as ownername, email, mobile, photopath, audit_createdt from rs_tblowner where ownerid=@ownerid and companyid=@companyid";
                SqlCommand myCommand;
                SqlParameter param;
                SqlConnection myConnection;
                myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[GetRSCompanyConnectionString()].ToString());
                myCommand = new SqlCommand(strSQL, myConnection);
                SqlDataReader myDataReader;

                param = new SqlParameter();
                param.SqlDbType = SqlDbType.Int;
                param.ParameterName = "@CompanyID";
                param.Value = companyid;
                myCommand.Parameters.Add(param);

                param = new SqlParameter();
                param.SqlDbType = SqlDbType.Int;
                param.ParameterName = "@OwnerID";
                param.Value = ownerid;
                myCommand.Parameters.Add(param);

                myConnection.Open();
                myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
                if (myDataReader.HasRows)
                {
                    myDataReader.Read();
                    //Header Info
                    lblOwnerName.Text = myDataReader["ownername"].ToString();
                    lblEmail.Text = myDataReader["email"].ToString();
                    lblMobile.Text = myDataReader["mobile"].ToString();

                    if (myDataReader["photopath"] != DBNull.Value)
                    {
                        imgOwner.ImageUrl = myDataReader["photopath"].ToString();
                    }
                    if (myDataReader["Audit_CreateDt"] != DBNull.Value)
                    {
                        DateTime createdt = Convert.ToDateTime(myDataReader["Audit_CreateDt"].ToString());
                        lblCreateDate.Text = createdt.ToShortDateString();
                    }
                }
            }
            return bHasValue;

        }
    }
}